<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'Trade history' );

$game_turn = getCurrentTurn();
$query = "SELECT * FROM trade_value WHERE turn > " . ( $game_turn - 60 ) . " ORDER BY turn DESC";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$num = mysql_numrows( $result );

if( $num > 0 ) {
?>    
    				<table id="twothird">
    					<th colspan="6"><?php transprint( 'Trade history (last 60 days)' ); ?></th>
    					<tr>
    						<td>When</td>
    						<td align="right">
    							<strong class="iron"><?php transprint( 'Iron' ); ?></strong> <?php transprint( 'for' ); ?> <strong class="gold"><?php transprint( 'Gold' ); ?></strong> 
    						</td>
    						<td align="right">
    							<strong class="coal"><?php transprint( 'Coal' ); ?></strong> <?php transprint( 'for' ); ?> <strong class="gold"><?php transprint( 'Gold' ); ?></strong>
    						</td>
    					</tr>
<?php
    $i = 0;
    while ( $i < $num ) {
        if( $i % 2 == 0 ) {
            print "<tr id=\"even\">";
        }
        else {
            print "<tr>";
        }
        
        $turn = $game_turn - mysql_result( $result, $i, "turn" );
        if( $turn == 0 ) {
        	$turn = translate( "Yesterday" );
        }
        else {
        	$turn = ( $turn + 1 ) . " " . translate( "days ago" );
        }
       
        print( "<td>$turn</td>" );
        
        if( mysql_result( $result, $i, "iron_gold" ) != 0 ) {
        	print( "<td align=\"right\"><strong class=\"iron\">1</strong> " . translate( "iron for" ) . " <strong class=\"gold\">" . round( mysql_result( $result, $i, "iron_gold" ), 2 ) . "</strong> " . translate( "gold" ) . "</td>" );
        }
        else {
        	print( "<td align=\"right\">-</td>" );
        }
        if( mysql_result( $result, $i, "coal_gold" ) != 0 ) {
        	print( "<td align=\"right\"><strong class=\"coal\">1</strong> " . translate( "coal for" ) . " <strong class=\"gold\">" . round( mysql_result( $result, $i, "coal_gold" ), 2 ) . "</strong> " . translate( "gold" ) . "</td>" );
        }
        else {
        	print( "<td align=\"right\">-</td>" );
        }
        print( "</tr>\r\n" );
        $i ++;
    }
?>
					</table>
<?php
}
else {
?>
	    			<div class="blok">
	    				<?php transprint( 'No trade history for the past 60 days.' ); ?>
	    			</div>
<?php
}
aos_footer();
?>